package com.example.donghuihui.androidframe;

import android.app.Application;
import android.graphics.Bitmap;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.zhy.http.okhttp.OkHttpUtils;

import org.xutils.x;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

public class BaseApplication extends Application{
    private static BaseApplication instance;
    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        x.Ext.init(this);//xutils初始化
        x.Ext.setDebug(true);//打包上线时改为false

        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(10, TimeUnit.SECONDS)
                .build();//okhttputils初始化
        OkHttpUtils.initClient(client);
        Picasso build = new Picasso.Builder(this)
                .loggingEnabled(true)//调试信息
                .defaultBitmapConfig(Bitmap.Config.RGB_565)//图片质量
                .indicatorsEnabled(true)//调试标记     打包上线时改为false
                .build();//初始化Picasso
        Picasso.setSingletonInstance(build);
    }
    /**
     * BaseApplication上下文对象
     * @return
     */
    public static BaseApplication getInstance() {
        return instance;
    }
    /**
     * 全局变量 弹Toast
     * @param str
     */
    public void showToast(String msg) {
//        ToastUtil.showToast(this, str);
        Toast.makeText(this,msg, Toast.LENGTH_SHORT).show();
    }
}
